﻿@namespace SwashbucklerDiary.Components
@implements IDisposable

<FabTransition>
    <MButton Class="my-btn-fab elevation-2"
             Bottom="true"
             Right="true"
             Fixed="true"
             Fab="true"
             Large="Desktop"
             OnClick="OnClick">
        <MIcon>
            @Icon
        </MIcon>
    </MButton>
</FabTransition>

@code {
    [Inject]
    private MasaBlazor MasaBlazor { get; set; } = default!;

    [Parameter]
    public string? Icon { get; set; }

    [Parameter]
    public EventCallback<MouseEventArgs> OnClick { get; set; }

    public void Dispose()
    {
        MasaBlazor.BreakpointChanged -= InvokeStateHasChanged;
        GC.SuppressFinalize(this);
    }

    protected override Task OnInitializedAsync()
    {
        MasaBlazor.BreakpointChanged += InvokeStateHasChanged;
        return base.OnInitializedAsync();
    }

    private bool Desktop => MasaBlazor.Breakpoint.MdAndUp;

    private void InvokeStateHasChanged(object? sender, BreakpointChangedEventArgs e)
    {
        InvokeAsync(StateHasChanged);
    }
}
